//
//  ViolationTableViewCell.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/4/14.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import Foundation
import UIKit
import SnapKit
class ViolationTableViewCell:UITableViewCell{
    var orderId,carNumLabel,violationCodeLabel,violationAddressLabel,orderAmountLabel,orderSubmitTimeLabel,orderNo,opTime: UILabel!
    var stateBtn:UIButton!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.backgroundColor = tableBgColor
        self.setupMainView()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupMainView() {
        // 背景view
        let backgroundView = UIView()
        backgroundView.layer.borderColor = colorFromHex(0xeeeeee).cgColor
        backgroundView.layer.borderWidth = 1
        backgroundView.layer.cornerRadius = 5
        backgroundView.layer.masksToBounds = true
        backgroundView.backgroundColor = UIColor.white
        self.addSubview(backgroundView)
        backgroundView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(5)
            make.top.equalTo(self).offset(5)
            make.right.equalTo(self).offset(-5)
            make.bottom.equalTo(self)
        }
        //车牌
        carNumLabel = UILabel()
        carNumLabel.font = UIFont.systemFont(ofSize: 13)
        backgroundView.addSubview(carNumLabel)
        carNumLabel.snp.makeConstraints { (make) in
            make.height.equalTo(35)
            make.top.equalTo(backgroundView)
            make.left.equalTo(backgroundView).offset(5)
            make.width.equalTo(carNumLabel.snp.width)
        }
        //状态
        stateBtn = UIButton()
        stateBtn.setTitleColor(appMainColor, for: .normal) //普通状态下文字的颜色
        stateBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        backgroundView.addSubview(stateBtn)
        stateBtn.snp.makeConstraints { (make) in
            make.top.equalTo(backgroundView)
            make.right.equalTo(backgroundView).offset(-5)
            make.height.equalTo(35)
        }
        //长分割线
        let longSeparator = UILabel()
        longSeparator.backgroundColor = appMainColor
        backgroundView.addSubview(longSeparator)
        longSeparator.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(stateBtn.snp.bottom).offset(1)
            make.left.equalTo(backgroundView).offset(5)
            make.right.equalTo(backgroundView).offset(-5)
        }
        //订单编号
        orderNo = UILabel()
        orderNo.font = UIFont.systemFont(ofSize: 12)
        backgroundView.addSubview(orderNo)
        orderNo.snp.makeConstraints { (make) in
            make.top.equalTo(longSeparator.snp.bottom)
            make.left.equalTo(backgroundView).offset(20)
            make.height.equalTo(22)
        }
        //处理时间
        opTime = UILabel()
        opTime.textColor = UIColor.lightGray
        opTime.font = UIFont.systemFont(ofSize: 11)
        backgroundView.addSubview(opTime)
        opTime.snp.makeConstraints { (make) in
            make.top.equalTo(orderNo.snp.bottom)
            make.left.equalTo(backgroundView).offset(20)
            make.height.equalTo(22)
        }
        //短割线
        let shortSeparator = UILabel()
        shortSeparator.backgroundColor = appMainColor
        backgroundView.addSubview(shortSeparator)
        shortSeparator.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(opTime.snp.bottom).offset(1)
            make.left.equalTo(backgroundView).offset(20)
            make.right.equalTo(backgroundView).offset(-5)
        }
        //金额
        orderAmountLabel = UILabel()
        orderAmountLabel.textColor = UIColor.red
        orderAmountLabel.font = UIFont.systemFont(ofSize: 13)
        backgroundView.addSubview(orderAmountLabel)
        orderAmountLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(backgroundView)
            make.left.equalTo(backgroundView).offset(20)
            make.height.equalTo(35)
        }
        //订单提交时间
        orderSubmitTimeLabel = UILabel()
        orderSubmitTimeLabel.font = UIFont.systemFont(ofSize: 13)
        backgroundView.addSubview(orderSubmitTimeLabel)
        orderSubmitTimeLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(backgroundView)
            make.right.equalTo(backgroundView).offset(-5)
            make.height.equalTo(35)
        }
    }
    func configCellDateWithModel(_ model:OrderModel) {
        carNumLabel.text = model.carNum
        var butTitle = ""
        if "0" == model.ostatus {
            butTitle = "未支付"
        }
        if "1" == model.ostatus {
            butTitle = "待处理"
        }
        if "2" == model.ostatus {
            butTitle = "处理中"
        }
        if "3" == model.ostatus {
            butTitle = "完成"
        }
        stateBtn.setTitle(butTitle, for: .normal)
        orderNo.text = "订单号：\(model.orderNo)"
        opTime.text = "处理时间：\(model.opTime)"
        orderAmountLabel.text = "￥\(model.totalAmount)"
        orderSubmitTimeLabel.text = "下单时间：\(model.subTime)"
    }
}
